#include <iostream>
#include <vector>

using namespace std;

static int func(int num) {
    static const vector<int> v {
        0, 1, 32, 243, 1024, 3125, 7776, 16807, 32768, 59049
    };
    int a = num % 10;
    int b = num / 10 % 10;
    int c = num / 100 % 10;
    int d = num / 1000 % 10;
    int e = num / 10000 % 10;
    int f = num / 100000 % 10;
    if (v[a] + v[b] + v[c] + v[d] + v[e] + v[f] == num)
        cout << num << endl;
    return v[a] + v[b] + v[c] + v[d] + v[e] + v[f] == num ? num : 0;
}

int main() {
    int sum = 0;
    for (int i = 2; i < 354295; i++) {
        sum += func(i);
    }
    cout << sum << endl; // 240559
}

